import DBConnection from "../../service/unit/mysql/DBConnection";
interface IData {
    name:string
    password:string
}

const TABLE_NAME = 'user';
export default async function register (conn:DBConnection, data:IData) {
    const result = await query(conn,data);
    if(result.length>0){
        return 1;
    }else{
        return insert(conn, data);
    }
}

function insert(conn:DBConnection, data:IData) {
    const {name, password} = data;
    return conn.Insert.insert(TABLE_NAME,{name,password});
}

function query(conn:DBConnection, data:IData) {
    const {name, password} = data;
    return conn.Query.queryWhere(TABLE_NAME,{name,password});
}